package dome_012;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>Description: [有N张火车票，每张票都有一个编号
 * 同时有10个窗口对外售票
 * 请写一个模拟程序
 * <p>
 * 分析下面的程序可能会产生哪些问题
 * 重复销售？超量销售？]</p>
 * Created on 2020/12/14
 *
 * @author <a href="mailto: 819712047@qq.com">谢振东 </a>
 * @version 1.0
 */
public class TicketSeller1 {
    private static List<String> tickets = new ArrayList<>();

    static {
        for (int i = 0; i < 10000; i++) {
            tickets.add("票编号：" + i);
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                while (tickets.size() > 0) {
                    String ticket = tickets.remove(0);
                    System.out.println(Thread.currentThread().getName() + "销售了>>>>>" + ticket);
                }
            }, "Thread" + (i + 1)).start();
        }
    }
}
